package linear;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;

public class LFeature implements Serializable{
	
	//ad, ader, query, pur, title, des, user
	
	private static final long serialVersionUID = -2461923165674659326L;
	public ArrayList<HashMap<Integer, Integer>> clickinfo = new ArrayList<HashMap<Integer,Integer>>();
	public ArrayList<HashMap<Integer, Integer>> imprinfo = new ArrayList<HashMap<Integer,Integer>>();
	
	public double[] mean;
	public double imean;
	
	public int getMapIndex(String tag){
		if (tag.equals("ad")){
			return 0;
		}else if (tag.equals("ader")){
			return 1;
		}else if (tag.equals("query")){
			return 2;
		}else if (tag.equals("pur")){
			return 3;
		}else if (tag.equals("title")){
			return 4;
		}else if (tag.equals("des")){
			return 5;
		}else if (tag.equals("user")){
			return 6;
		}else if (tag.equals("pos")){
			return 7;
		}else if (tag.equals("sex")){
			return 8;
		}else return 9;//age
	}
	
	public LFeature(){
		mean = new double[10];
		for (int i = 0; i < 10; i++){
			HashMap<Integer, Integer> c_map = new HashMap<Integer, Integer>();
			HashMap<Integer, Integer> i_map = new HashMap<Integer, Integer>();
			clickinfo.add(c_map);
			imprinfo.add(i_map);
		}
	}
	
	public static void writeFeature(LFeature l, String path){
		try{
			ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(path));
			out.writeObject(l);
			out.flush();
			out.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public static LFeature readFeature(String path){
		LFeature l = null;
		try{
			ObjectInputStream in = new ObjectInputStream(new FileInputStream(path));
			l = (LFeature) in.readObject();
			in.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		return l;
	}
	
}
